package com.lsa.southwind.controller;


import com.lsa.southwind.form.SearchForm;
import com.lsa.southwind.service.MoveoutService;
import com.lsa.southwind.util.ResultVoUtil;
import com.lsa.southwind.vo.PageVo;
import com.lsa.southwind.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/moveout")
public class MoveoutController {
    @Autowired
    private MoveoutService moveoutService;

    @GetMapping("/list/{page}/{size}")
    public ResultVo list(@PathVariable Integer page, @PathVariable Integer size) {
        PageVo list = this.moveoutService.list(page, size);
        return ResultVoUtil.success(list);
    }

    /*模糊查询*/
    @GetMapping("/search")
    public ResultVo search(SearchForm searchForm) {
        PageVo search = this.moveoutService.search(searchForm);

        return ResultVoUtil.success(search);
    }

    @PutMapping("/moveout/{id}/{reason}")
    public ResultVo moveout(@PathVariable("id") Integer id, @PathVariable("reason") String reason) {
        Boolean moveout = this.moveoutService.moveout(id, reason);
        if (!moveout) return ResultVoUtil.fail();
        return ResultVoUtil.success(null);
    }

    /*学生迁出列表*/
    @GetMapping("/moveoutList/{page}/{size}")
    public ResultVo moveoutList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        PageVo moveoutList = this.moveoutService.moveoutList(page, size);

        return ResultVoUtil.success(moveoutList);
    }

    @GetMapping("/moveoutSearch")
    public ResultVo moveoutSearch(SearchForm searchForm) {
        PageVo pageVo = this.moveoutService.moveoutSearch(searchForm);
        return ResultVoUtil.success(pageVo);
    }
}

